package com.uniledger.exchange.wallet;

import android.content.Context;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.uniledger.exchange.R;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 *  上面已选择
 */
public class VerifyBackupSelectedMnemonicWordsAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {

    List<Mnemonic> list;
    Context context;
    LayoutInflater inflater;

    public VerifyBackupSelectedMnemonicWordsAdapter(Context context) {
        this.context = context;
        this.list = new ArrayList<>();
        this.inflater = LayoutInflater.from(context);
    }

    public List<Mnemonic> getList() {
        return list;
    }

    public void addItem(Mnemonic mnemonic) {
        this.list.add(mnemonic);
        notifyDataSetChanged();
    }
    public void addItems(List<Mnemonic> mnemonic) {
        this.list.addAll(mnemonic);
        notifyDataSetChanged();
    }


    @NonNull
    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View convertView = inflater.inflate(R.layout.list_item_mnemoic_selected, parent, false);
        return new VH(convertView);
    }

    @Override
    public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) {
        VH vh = (VH) holder;
        Mnemonic mnemonic = list.get(position);
        vh.text.setText(mnemonic.word);
    }

    @Override
    public int getItemCount() {
        return list.size();
    }

    static class VH extends RecyclerView.ViewHolder {
        @BindView(R.id.tv_mnemonic_selected_word)
        TextView text;

        public VH(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }

    public void remove(int position){
        list.remove(position);
        notifyDataSetChanged();
    }

}
